import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginView from '../views/LoginView.vue'
import RegistryView from '../views/RegistryView.vue'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        component: LoginView,
        meta: {
            title: '用户登录'
        }
    },
    {
        path: '/register',
        component: RegistryView,
        meta: {
            title: '用户注册'
        }
    },
    {
        path: '/admin/index',
        component: () => import('../views/admin/IndexView.vue'),
        meta: {
            title: '网站首页'
        }
    },
    {
        path: '/admin/reslist',
        component: () => import('../views/admin/ResListView.vue'),
        meta: {
            title: '资源列表'
        }
    },
    {
        path: '/admin/resdetail',
        component: () => import('../views/admin/ResDetailView.vue'),
        meta: {
            title: '资源详情'
        }
    }
    // {
    //     path: '/admin',
    //     redirect: '/admin/user/list',
    //     component: () => import('../views/admin/IndexView.vue'),
    //     children: [
    //         {
    //             path: 'user/list', //     /admin/user/list
    //             component: () => import('../views/admin/IndexView.vue'),
    //             meta: {
    //                 title: '用户管理'
    //             }
    //         },
    //         {
    //             path: 'role/list', // /admin/user/list
    //             component: () => import('../views/admin/ResListView.vue'),
    //             meta: {
    //                 title: '角色管理'
    //             }
    //         },
    //         {
    //             path: 'permission/list', // /admin/user/add-new
    //             component: () => import('../views/admin/ResDetailView.vue'),
    //             meta: {
    //                 title: '权限管理'
    //             }
    //         }
    //
    //     ]
    // }
    // ,
    // {
    //     path: '/manage',
    //     redirect: '/manage/product/list',
    //     component: () => import('../views/AdminView.vue'),
    //     children: [
    //         {
    //             path: 'product/list', //     /manage/product/list
    //             component: () => import('../views/manage/ProductView.vue'),
    //             meta: {
    //                 title: '商品管理'
    //             }
    //         },
    //         {
    //             path: 'categorys/list', //     /manage/categorys/list
    //             component: () => import('../views/manage/CategorysView.vue'),
    //             meta: {
    //                 title: '分类管理'
    //             }
    //         },
    //         {
    //             path: 'order/list', //     /manage/order/list
    //             component: () => import('../views/manage/OrderView.vue'),
    //             meta: {
    //                 title: '订单管理'
    //             }
    //         },
    //         {
    //             path: 'purchase/list', //     /manage/purchase/list
    //             component: () => import('../views/manage/PurchaseView.vue'),
    //             meta: {
    //                 title: '采购管理'
    //             }
    //         },
    //         {
    //             path: 'count/list', //     /admin/count/list
    //             component: () => import('../views/manage/CountView.vue'),
    //             meta: {
    //                 title: '统计管理'
    //             }
    //         }
    //
    //     ]
    // }


]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    next()
})

export default router
